package com.woniu.controller;

import com.woniu.entity.Atten;
import com.woniu.entity.Vacate;
import com.woniu.entity.response.ResponseEntity;
import com.woniu.entity.vo.PageResponseVo;
import com.woniu.service.IVacateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hyl
 * @since 2022-08-28
 */
@Controller
@RequestMapping("/brain/vacate")
public class VacateController {
    @Autowired
    private IVacateService vacateService;

    @PostMapping("/create")
    public ResponseEntity createVacate(@RequestBody Vacate vacate) {
        vacateService.create(vacate);
        return ResponseEntity.success("");
    }

    @PostMapping("/approval/pass")
    public ResponseEntity approvalPassVacate(@RequestBody Vacate vacate) {
        vacateService.approvalPass(vacate);
        return ResponseEntity.success("");
    }

    @PostMapping("/approval/fail")
    public ResponseEntity approvalFailVacate(@RequestBody Vacate vacate) {
        vacateService.approvalPass(vacate);
        return ResponseEntity.success("");
    }

    @PostMapping("/pagebyterms")
    public ResponseEntity selectVacateByTerms(@RequestParam(required = false, defaultValue = "0") Integer page,
                                                      @RequestParam(required = false, defaultValue = "10") Integer count,
                                                      @RequestBody Vacate vacate) {
        PageResponseVo<Vacate> p = vacateService.getVacatePageByTerms(page, count, vacate);
        return ResponseEntity.success(p);
    }

    @PostMapping("/vacatedetails")
    public ResponseEntity selectVacateDetails(@RequestParam Integer vacateId) {
        Vacate v = vacateService.queryVacateDetails(vacateId);
        return ResponseEntity.success(v);
    }

}
